#@layoutT('数据源')
#define main()
<div class="container-wrap">
   #@formStart()
      #@queryStart('关键词查询')
   <input type="search" name="keyword" autocomplete="off" class="layui-input" placeholder="搜索关键词" style="padding-left:20px"/>
   <i class="layui-icon layui-icon-search" style="position: absolute;top:7px;left:2px"></i>
      #@queryEnd()
   #@formEnd()
   
	###初始化隐藏按钮
    #set(add=false,edit=false,del=false)
    
    #if(vs.funcMap.get('data_source_add'))
        #set(add=true)
    #end
    
    #if(vs.funcMap.get('data_source_update'))
        #set(edit=true)
    #end
    
    #if(vs.funcMap.get('data_source_delete'))
        #set(del=true)
    #end
   #@table()
</div>
#end
#define buttonRow()
	<a class="layui-btn layui-btn-xs" lay-event="debug">测试链接</a>
#end
#define js()
<!-- 分页表格 -->
<script>
function debugFunc(obj){
	var id=obj.data.id;
	var url="#(path)/portal/core/dataSource/debug/"+id;
	$.post(url,function(ret){
		if(ret.state=='ok')
			success(ret.msg);
		else 
			warn(ret.msg)
	});
}
    gridArgs.title='数据源';
    gridArgs.dataId='id';
    gridArgs.deleteUrl='#(path)/portal/core/dataSource/delete';
    gridArgs.updateUrl='#(path)/portal/core/dataSource/edit/';
    gridArgs.addUrl='#(path)/portal/core/dataSource/add';
    gridArgs.gridDivId ='maingrid';
    initGrid({id : 'maingrid'
        ,elem : '#maingrid'
        ,toolbar:'#table_toolbar'//开启头部工具栏，并为其绑定左侧模板
        ,cellMinWidth: 100
        ,cols : [ [
				 {title: '主键',field : 'id',width : 35,checkbox : true},
				 {title:'序号',type:'numbers',width:35},
				 {title:'数据库 / 标题',field:'title',templet:function(obj){
						return obj.db_type+" / "+obj.title;
				 }},
				 {title:'configName',field:'config_name'},
				 {title:'user',field:'user'},
				 {title:'password',field:'password',hide:true},
				 {title:'jdbcUrl',field:'jdbc_url'},
				 
				 ### 字段权限控制
				 #if(vs.funcMap.get('data_source_state'))
				 {title:'开机启动',field:'state',templet:'#stateSwitch'},
				 #end
				 
				 #if(vs.funcMap.get('data_source_start'))
				 {title:'启动',field:'start',templet:'#startSwitch'},
				 #end
				 
				 {title:'创建时间',field:'create_time',hide:true},

            {fixed:'right',width : 200,align : 'left',toolbar : '#bar_maingrid'}
            ] ]
        ,url:"#(path)/portal/core/dataSource/list"
        ,searchForm : 'searchForm'
    },{debug:debugFunc});

	  //监听表单操作
	  layui.form.on('switch(stateFilter)', function(obj){
		 var id = obj.value;
		 var checked=obj.elem.checked;
		 var state=0;
		 if(checked){
		    state=1
		 }
		
      $.post("#(path)/portal/core/dataSource/updateFieldValue",param({
			'dataSource.id' : id
			,'dataSource.state':state
		}),function(ret) {
			if (ret.state=='ok') {
				layer.tips(ret.msg, obj.othis);
			} else {
				$(".layui-laypage-btn").click();
				layer.alert(ret.msg);
			}
		});
	  });

	  layui.form.on('switch(startFilter)', function(obj){
			 var id = obj.value;
			 var checked=obj.elem.checked;
			 var start=0;
			 if(checked){
			    start=1
			 }
			
	      $.post("#(path)/portal/core/dataSource/start",param({
				'id' : id
				,'start':start
			}),function(ret) {
				if (ret.state=='ok') {
					layer.tips(ret.msg, obj.othis);
				} else {
					$(".layui-laypage-btn").click();
					layer.alert(ret.msg);
				}
			});
		  });
</script>
#end
<script type="text/html" id="stateSwitch">
  		<input type="checkbox" name="state" value="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="stateFilter" {{ d.state == 1 ? 'checked ' : '' }} >
</script> 
<script type="text/html" id="startSwitch">
  		<input type="checkbox" name="start" value="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="startFilter" {{ d.start == 1 ? 'checked ' : '' }} >
</script> 

